﻿@model PagedList<View_SaleSettlement>
@{
    ViewBag.Title = "销售结算明细";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";


    SaleSettleListQueryModel paramModel = new SaleSettleListQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (SaleSettleListQueryModel)ViewBag.paramModel;
    }
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("salesettlementlist", "finance")" method="get">
    <div class="form_query">
        <div>
            手机号：
            <input type="text" name="account_mobile" id="account_mobile" class="abc input-default" placeholder="" value="@paramModel.account_mobile">&nbsp;
        </div>
        <div>
            会员名称：
            <input type="text" name="member_name" id="member_name" class="abc input-default" placeholder="" value="@paramModel.member_name">&nbsp;
        </div>
        <div>
            代购编号：
            <input type="text" name="replace_buyer_NO" id="replace_buyer_NO" class="abc input-default" placeholder="" value="@paramModel.replace_buyer_NO">&nbsp;
        </div>
        <div>
            是否结算：
            <select id="is_settled" name="is_settled">
                <option value="-10" @(paramModel.is_settled == -10 ? "selected" : "")>全部</option>
                @{
                    dc = new Dictionary<string, string>();
                    dc.Add("0", "否");
                    dc.Add("1", "是");
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.is_settled.ToString());
            </select>&nbsp;
        </div>
        <div>
            销售日期：
            <input type="text" name="beg_time" class="calendar" id="beg_time" value="@paramModel.beg_time.ToString(2)"> - <input type="text" name="end_time" class="calendar" id="end_time" value="@paramModel.end_time.ToString(2)">&nbsp;
        </div>
        <div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div><div>
            <button type="submit" class="btn btn-primary">查询</button>&nbsp;&nbsp;<button type="button" class="btn btn-success" id="moresettle" onclick="toMoreSettlement()">批量结算</button>
            <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
        </div>
    </div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:40px"><input type="checkbox" name="chkall" id="chkall" />全选</th>
            <th>代购编号</th>
            <th>手机号</th>
            <th>会员名称</th>
            <th>销售日期</th>
            <th>销售金额</th>
            <th>服务费</th>
            <th>推荐费</th>
            <th>是否结算</th>
            <th>结算时间</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>
                    @if (m.is_settled == 0)
                    {
                        <input type="checkbox" name="cbx_last" value="@m.seq_id" />
                    }
                </td>
                <td>@m.replace_buyer_NO</td>
                <td>@m.account_mobile</td>
                <td>@m.member_name</td>
                <td>@m.sale_date.ToString(6)</td>
                <td>@m.sale_money</td>
                <td>@m.buyer_money</td>
                <td>@m.recommend_money</td>
                <td>
                    @switch (m.is_settled)
                    {
                        case 1:
                            @:<div class="green">是</div>
                            break;
                        case 0:
                            @:<div class="red">否</div>
                            break;
                    }
                </td>
                <td>@m.settlement_time.ToString(1)</td>
                <td>
                    @if (m.is_settled == 0)
                    {
                        <a href="javascript:void(0);" onclick="toSettlement(@m.seq_id)">结算</a>
                    }
                    &nbsp; <a href="salesettlementinfo?date=@m.sale_date.ToString(6)&uid=@m.uid">查看详情</a>
                </td>
            </tr>
        }
    }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"] | 总销售金额：@ViewData["AllSaleMoney"] | 总代购金额：@ViewData["AllBuyerMoney"] | 总推荐金额：@ViewData["AllRecommendMoney"]
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    reloadHandler = function () {
        window.location.reload();
    }

    function toSettlement(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要结算吗?',
            icon: 'question',
            buttons: [
                {
                    text: '确定',
                    elCls: 'button button-primary',
                    handler: function () {
                        url = "@Url.Action("toSettlement", "finance")";
                        parameter = { id: id };
                        $.post(url, parameter, function (result) {
                                    ShowActionResult(result, reloadHandler);
                        });
                        his.close();
                        }
                    },
                {
                        text: '取消',
                        elCls: 'button',
                        handler: function () {
                           this.close();
                    }
                }
            ]
        });
    }

    function toMoreSettlement() {
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要结算的数据", 'warning');
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '确定要将选择的销售明细都结算吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("toMoreSettlement", "finance")";
                      parameter = {
                        ids: ids
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }
            ]
        });
    }
</script>